import { Component, OnInit } from '@angular/core';
import { Singlepage } from '../../model/singlepage';
import { HttpClient } from '@angular/common/http';
import { ActivatedRoute, Router } from '@angular/router';
import { SinglepageService } from '../../service/singlepage.service';

@Component({
  selector: 'app-uploadpage',
  templateUrl: './uploadpage.component.html',
  styleUrls: ['./uploadpage.component.css']
})
export class UploadpageComponent implements OnInit {
  al:Array<Singlepage>;
  constructor(
    private http:HttpClient,
    private routerinfo:ActivatedRoute,
    private router:Router,
    private singlepagelistservice:SinglepageService
  ) {
    this.al = new Array();
   }

  ngOnInit() {
    this.loadSiniglepageList();
  }

  private loadSiniglepageList(){
    this.al = new Array();
    this.singlepagelistservice.getSinglepageList()
    .then((data:any)=>{
      this.al = data;
    })
  }

  addSinglepage(){
    this.router.navigate(['editsinglepage','add']);
  }



  updateSinglepage(id:string){
    this.router.navigate(['editsinglepage',id]);
  }


  deleteSinglepage(id:string){
    this.singlepagelistservice.deleteSinglepage(id)
    .then((flag:boolean)=>{
      if(flag==true){
        this.loadSiniglepageList();
      }else{
        alert("删除异常,请刷新后重试");
      }
    })
  }
}
